package com.example.laboratory.root_ui.AddUser;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.example.laboratory.R;
import com.example.laboratory.bean.User;
import com.example.laboratory.bean.UserList;
import com.example.laboratory.common.CommonUtils;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.ui.base.BaseActivity;
import com.example.laboratory.ui.base.BasePresenterActivity;

public class AddUserActivity extends BasePresenterActivity<AddUserPresenter> implements AddUserContact.IAddUserView {
    @BindView(R.id.job_number)
    EditText jobNumber;
    @BindView(R.id.add_user_name)
    EditText addUserName;
    @BindView(R.id.init_password)
    EditText initPassword;
    @BindView(R.id.user_depart)
    TextView userDepart;
    @BindView(R.id.tel_phone)
    EditText telPhone;
    @BindView(R.id.permission)
    Spinner permission;
    @BindView(R.id.add_labs)
    Button addLabs;

    CommonUtils commonUtils=new CommonUtils();
    UserList.UserListBean user=new UserList.UserListBean();

    @Override
    protected AddUserPresenter createPresenter() {
        return new AddUserPresenter();
    }

    @Override
    protected boolean initToolbar() {
        mToolbar.setTitle("新增安全员");
        return true;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_user;
    }

    @Override
    protected void initViews() {
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        userDepart.setText(commonUtils.getDepartName(UserInfoManager.getUserInfo().getDepartId()));

    }


    @OnClick(R.id.add_labs)
    public void onViewClicked() {
        user.setPassword(initPassword.getText().toString());
        user.setJobNumber(jobNumber.getText().toString());
        user.setPermission("1");
        user.setDepartId(commonUtils.getDepartId(userDepart.getText().toString()));
        user.setTel(telPhone.getText().toString());
        user.setUsername(addUserName.getText().toString());
        mPresenter.addUser(user);
    }

    @Override
    public void showResult(String msg) {

    }
}
